找传奇、传世资源到传世资源站!

串口调试助手源码

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

串口调试助手工具的源代码
串口调试助手源码 C#多媒体编程-第1张
  private void SendButton_MouseUp(object sender, MouseEventArgs e)
        {
            SendButton.Image = 串口调试.Properties.Resources.Send_MouseEnter;
            if (!COM.IsOpen)
            {
                ShowSysMessage(Color.Red, "请打开一个端口!");
                return;
            }
            if (SendtextBox.TextLength == 0)
            {
                ShowSysMessage(Color.Red, "请输入数据!");
            }
            else
            {
                if (HexSendChecked)  //16进制发送
                {
                    if (SendtextBox.Text.Length > 2)   //大于两个字符
                    {
                        ShowSysMessage(Color.Red, "格式错误,请输入一个十六进制数!");
                        SendtextBox.Clear();
                    }
                    else if (SendtextBox.Text.Length == 2)  //两个字符
                    {
                        char byteH = SendtextBox.Text[0];
                        char byteL = SendtextBox.Text[1];
                        if (ascIItoHex(ref byteH) && ascIItoHex(ref byteL))
                        {
                            byte[] b = new byte[1];
                            b[0] = (byte)((byteH << 4) | byteL);
                            COM.Write(b, 0, 1);
                            ShowSysMessage(Color.YellowGreen, "0x" SendtextBox.Text);
                            SendtextBox.Clear();
                        }
                        else  //输入不为0~9 A~F a~f
                        {
                            ShowSysMessage(Color.Red, "格式错误,请输入一个十六进制数!");
                            SendtextBox.Clear();
                        }
                    }
                    else  //一个字符
                    {                       
                        char c = SendtextBox.Text[0];
                        if (ascIItoHex(ref c))
                        {
                            byte[] b = new byte[1];
                            b[0] = (byte)c;
                            COM.Write(b, 0, 1);
                            ShowSysMessage(Color.YellowGreen, "0x0" SendtextBox.Text);
                            SendtextBox.Clear();
                        }
                        else
                        {
                            ShowSysMessage(Color.Red, "格式错误,请输入一个十六进制数!");
                            SendtextBox.Clear();
                        }
                    }
                }
                else  //ASCII 发送
                {
                    COM.Write(SendtextBox.Text);
                    ShowSysMessage(Color.YellowGreen, SendtextBox.Text);
                    SendtextBox.Clear();
                }
            }           
        }        bool HexShowChecked = false;
        private void HexCheckpictureBox_MouseEnter(object sender, EventArgs e)
        {
            if (HexShowChecked)
            {
                HexCheckpictureBox.Image = 串口调试.Properties.Resources.CheckboxCheckedEnter;
            }
            else
            {
                HexCheckpictureBox.Image = 串口调试.Properties.Resources.CheckboxNoCheckEnter;
            }           
        }

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复